﻿using Canteen.Core.Models;
using Canteen.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Canteen.Core.WebApp.API.Controllers.Admin
{
    [Route("admin/shoporder")]
    [ApiController, Authorize]
    public class AdminShopOrderController : ControllerBase
    {
        #region 构造函数

        private readonly IShopOrderService shopOrderService;
        private readonly IStoreService storeService;
        public AdminShopOrderController(IShopOrderService shopOrderService, IStoreService storeService)
        {
            this.shopOrderService = shopOrderService ?? throw new ArgumentNullException(nameof(shopOrderService));
            this.storeService = storeService ?? throw new ArgumentNullException(nameof(storeService));
        }
        #endregion

        [HttpGet("PageList")]
        public async Task<HttpResult<dynamic>> GetPageList([FromQuery] ShopOrderPageParameters parameters)
        {
            parameters.StoreId = storeService.StoreId;
            return HttpResult<dynamic>.Success(await shopOrderService.GetPageList(parameters));
        }

        // DELETE /admin/shoporder/5
        [HttpDelete("{id}")]
        public async Task<HttpResult<bool>> Delete(int id)
        {
            return HttpResult<bool>.Success(await shopOrderService.DeleteShopOrder(id));
        }
    }
}
